//
// Created by xinyang on 19-7-31.
//
#include <systime.h>
#include <math.h>

#if defined Linux
#include <sys/time.h>
#elif defined Windows
#include <Windows.h>
#else
#error "nonsupport platform."
#endif

#if defined Linux

systime getsystime() {
	timeval tv;
	gettimeofday(&tv, nullptr);
	return (tv.tv_usec / 1000.0 + tv.tv_sec * 1000.0);
}

systime getsystime(systime &t) {
	static systime time_base = getsystime();
	timeval tv;
	gettimeofday(&tv, nullptr);
	t = (tv.tv_usec / 1000.0 + tv.tv_sec * 1000.0 - time_base);
	if(t> 100000000000000) time_base=getsystime();
}
//115292150460684700

#elif defined Windows

void getsystime(systime &t) {
	SYSTEMTIME tv;
	GetLocalTime(&tv);
	t = tv.wMilliseconds + tv.wSecond * 1000.0;
}

#else
//#error "nonsupport platform."
#endif


systime getTimeIntervalms(const systime &now, const systime &last) {
	systime t = now >= last ? now - last : (115292150460684700 - last) + now;
	return t;
}

